<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }
        
        li {
            width: 100px;
            list-style: none;
            /* float: left; */
            color: white;
            font-size: 30px;
            text-align: center;
        }
        
        ul {
            width: 100px;
            border: rgb(140, 64, 211) 2px solid;
            float: left;
        }
        
        #root {
            width: 500px;
            height: 300px;
            margin: 0 auto;
            /* background-color: rgb(231, 105, 105); */
            /* display: flex;
            flex-wrap: wrap; */
        }
    </style>
</head>

<body>

    <div id="root">
        <ul></ul>
        <ul></ul>
        <ul></ul>
        <ul></ul>
    </div>
</body>

</html>
<script>
    var root = document.querySelector("#root");
    // 随机数
    function shu(min, max) {
        return Math.floor(Math.random() * (max - min + 1) + min);
    }

    // 随机颜色;
    function clo() {
        return shu(0, 255);
    }
    //随机高;
    function gao() {
        return shu(100, 300);
    }
    var ul = document.querySelectorAll("ul");
    var j = 0
    console.log(ul);
    var ulh = [];
    for (var i = 0; i < 50; i++) {
        var li = document.createElement("li");
        li.innerHTML = i + 1;
        li.style.height = gao() + "px";
        li.style.lineHeight = li.style.height;
        li.style.backgroundColor = "rgb(" + clo() + "," + clo() + "," + clo() + ")";
        if (i < 4) {
            ul[i].appendChild(li);
        } else {
            for (var a = 0; a < ul.length; a++) {
                ulh[a] = ul[a].clientHeight;
            }
            var ulh1 = ulh[0];
            var index = 0;
            for (var k = 0; k < ulh.length; k++) {
                if (ulh1 > ulh[k]) {
                    ulh1 = ulh[k];
                    index = k;
                }
            }
            ul[index].appendChild(li);
        }

    }
</script>